

package tomkitty;

import java.io.*;

public class TkErrorTurdlet extends Turdlet {

  protected String status;

  public void handle(Request req, Response resp) {
    status = resp.getStatus();
    resp.setStatus(HTTP_OK);

    super.handle(req, resp);
  }

  public void doit() {
    response.setStatus(status);
    String host = request.getOrigUri().getAuthority();

    Tag html, head, body, title, table1, table2, table3, tr, td, h1, img, code;

    html = new Tag("html");
    head = html.newChild("head");
    body = html.newChild("body");

    title = head.newChild("title");
    title.setContent(host + ": " + status);

    table1 = body.newChild("table");
    table1.setAttribute("height", "100%");
    table1.setAttribute("width", "100%");

    tr = table1.newChild("tr");
    td = tr.newChild("td");
    td.setAttribute("align", "middle");

    table2 = td.newChild("table");
    tr = table2.newChild("tr");
    td = tr.newChild("td");
    td.setAttribute("align", "middle");

    table3 = td.newChild("table");
    tr = table3.newChild("tr");
    td = tr.newChild("td");
    td.setAttribute("align", "middle");

    h1 = td.newChild("h1");
    code = h1.newChild("code");
    code.setContent(status);

    code = td.newChild("code");
    code.setContent("<i>To have no errors</br>would be life without meaning</br>no struggle, no joy</i>");

    tr = table2.newChild("tr");
    td = tr.newChild("td");
    td.setAttribute("align", "middle");

    table3 = td.newChild("table");
    table3.setAttribute("cellpadding", "10px");
    tr = table3.newChild("tr");
    td = tr.newChild("td");
    td.setAttribute("align", "middle");

    tr = table2.newChild("tr");
    td = tr.newChild("td");
    td.setAttribute("align", "middle");

    table3 = td.newChild("table");
    table3.setAttribute("cellspacing", "7px");
    table3.setAttribute("bgcolor", "d0d0d0");

    tr = table3.newChild("tr");
    td = tr.newChild("td");
    td.setAttribute("align", "middle");
    img = td.newChild("img");
    img.setAttribute("src", "http://ubergibson.com/~micha/files/images/HelloKitty.jpg");

    tr = table3.newChild("tr");
    td = tr.newChild("td");
    td.setAttribute("align", "middle");
    code = td.newChild("code");
    code.setContent(Main.name + "/" + Main.version + " port " + context.getConfig().get(CONF_PORT));

    try {
      println(html.render());
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }

  }

}
